package com.edu.exam.entity.examination.paper.technical;

import com.edu.exam.enums.examination.paper.OmPriorityLevel;
import com.edu.exam.enums.examination.paper.OmSourceType;
import com.edu.exam.enums.examination.paper.OmTaskType;
import com.edu.exam.enums.examination.paper.PaperProcessingTaskStatus;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.Accessors;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

/**
 * OMR识别任务实体类
 *
 * 根据E-04-03 OMR识别子模块数据库设计实现
 * 存储OMR识别任务的基本信息、执行状态、进度情况等。
 *
 * @author System
 * @version 1.0.0
 */

@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class OmRecognitionTask {

    /**
     * 任务ID，主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "task_id")
    private Long taskId;

    /**
     * 任务基本信息
     */
    @Column(name = "task_name", length = 200, nullable = false)
    private String taskName;

    @Column(name = "task_description", columnDefinition = "TEXT")
    private String taskDescription;

    @Enumerated(EnumType.STRING)
    @Column(name = "task_type", length = 20, nullable = false)
    private OmTaskType taskType;

    @Enumerated(EnumType.STRING)
    @Column(name = "source_type", length = 20, nullable = false)
    private OmSourceType sourceType;

    /**
     * 关联信息
     */
    @Column(name = "batch_id")
    private Long batchId;

    @Column(name = "exam_id")
    private Long examId;

    @Column(name = "subject_id")
    private Long subjectId;

    @Column(name = "config_id", nullable = false)
    private Long configId;

    /**
     * 任务状态信息
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "task_status", length = 20, nullable = false)
    private PaperProcessingTaskStatus taskStatus;

    @Column(name = "progress", precision = 5, scale = 2)
    private Double progress;

    @Column(name = "current_step", length = 100)
    private String currentStep;

    /**
     * 时间信息
     */
    @Column(name = "started_time")
    private LocalDateTime startedTime;

    @Column(name = "completed_time")
    private LocalDateTime completedTime;

    /**
     * 创建和修改人信息
     */
    @Column(name = "created_by", nullable = false)
    private Long createdBy;

    @Column(name = "updated_by")
    private Long updatedBy;

    /**
     * 统计信息
     */
    @Column(name = "total_sheets")
    private Integer totalSheets;

    @Column(name = "processed_sheets")
    private Integer processedSheets;

    @Column(name = "success_sheets")
    private Integer successSheets;

    @Column(name = "failed_sheets")
    private Integer failedSheets;

    /**
     * 任务参数
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "priority_level", length = 10, nullable = false)
    private OmPriorityLevel priorityLevel;

    @Column(name = "max_retry_count")
    private Integer maxRetryCount;

    @Column(name = "timeout_minutes")
    private Integer timeoutMinutes;

    // ===== 审计字段 =====

    /**
     * 创建时间
     */
    @CreationTimestamp
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 更新时间
     */
    @UpdateTimestamp
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    /**
     * 版本号（乐观锁）
     */
    @Version
    @Column(name = "version")
    private Integer version = 0;

    /**
     * 逻辑删除标记
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted = false;
}